package com.wenheng.Business;

import com.wenheng.service.SeckillingService;
import com.wenheng.vo.entity.Seckillproduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Auther: 文恒
 * @Date: 2021/3/25 - 03 - 25 -16:20
 * @Description:com.wenheng.Business
 * @version:1.0
 */
@Component
public class SeckillingBusiness {
    @Autowired
    SeckillingService seckillingService;
    //1.确认库存
    public Seckillproduct ConfirmInventory(Integer id, Integer activityId){
        return seckillingService.CommoditiesAndActivities(id,activityId);
    }
    //2.更改库存 3.生成订单 在service中进行

    //2 3 步骤合成一步
    public boolean ExecutiveBusiness(Integer id,Integer activityId,Integer NumSeckill,String token){
        Seckillproduct seckillproduct = ConfirmInventory(id,activityId);
        if(seckillproduct!=null){    //确认库存
            seckillproduct.setSold(NumSeckill);  //需要添加的库存数量
            if(seckillingService.ExecutiveBusiness(seckillproduct,token) == 200)  //生产订单 修改库存
            return true; //成功！！
        }else{
            return false;
        }
        return false;
    }
}
